import 'dart:async';
import 'dart:convert';
import 'dart:io';

/** 移动 */
Stream<String> _move(
    int annulus, String from, String middle, String to) async* {
  var msg = '环 $annulus from 柱 $from to 柱 $to';
  if (annulus == 1) {
    print('press [Enter] to continue...');
    stdin.readLineSync();
    yield msg;
  } else {
    yield* _move(annulus - 1, from, to, middle);
    print('press [Enter] to continue...');
    stdin.readLineSync();
    yield msg;
    yield* _move(annulus - 1, middle, from, to);
  }
}

/** 入口函数 */
void main(List<String> args) async {
  int steps = 0;
  await for (var msg in _move(3, 'A', 'C', 'B')) {
    steps++;
    print(msg);
  }
  print('\r\nTotal move [$steps] steps.');
}
